package com.zhisheng.users.controller;


import com.zhisheng.result.MyResponseResult;
import com.zhisheng.users.entity.Users;
import com.zhisheng.users.service.UsersService;
import com.zhisheng.utils.MyThreadLocal;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * (Users)表控制层
 *
 * @author 全哥
 * @since 2025-02-22 10:49:23
 */
@RestController
@RequestMapping("/users")
public class UsersController {
    /**
     * 服务对象
     */
    @Resource
    private UsersService usersService;

    /*
         注册功能
     */
    @PostMapping("/register")
    public MyResponseResult<String> register(@RequestBody Users users) {
        String res = usersService.mysave(users);
        return MyResponseResult.success(res);
    }

    /*
         登录功能
     */
    @PostMapping("/login")
    public MyResponseResult<String> login(@RequestBody Users users) {
        String token = usersService.login(users);
        return MyResponseResult.success(token);
    }

    @GetMapping("/{id}")
    public MyResponseResult<Users> getById(@PathVariable Integer id) {

        Users o = MyThreadLocal.get();
        System.out.println(o+"正在执行查询操作...........................................");

        Users users = usersService.getById(id);
        return MyResponseResult.success(users);
    }

}

